package com.love.marriage.personalImageryInfo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.love.marriage.common.interfaces.avoid.AvoidRepeatableCommit;
import com.love.marriage.common.validator.Update;
import com.love.marriage.common.vo.Result;
import com.love.marriage.common.vo.ResultBoolean;
import com.love.marriage.personalImageryInfo.service.PersonalImageryInfoService;
import com.love.marriage.personalImageryInfo.vo.PersonalImageryInfoVo;
import com.love.marriage.personalImageryInfo.vo.ResultPersonalImageryInfoVo;
import com.love.marriage.personalImageryInfo.vo.ResultPersonalImageryInfoVoList;
import com.love.marriage.personalImageryInfo.vo.ResultPersonalImageryInfoVoPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * description:  个人形象表restApi
 * author:       mybatisPlus
 * createDate:   2024-10-13 22:54:18
 * version:      1.0.0
 */
@ApiSort(105)
@Tag(name = "个人形象表相关接口", description = "个人形象表相关接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/personal-imagery-info")
public class PersonalImageryInfoController {

    private final PersonalImageryInfoService personalImageryInfoService;

    @ApiOperationSupport(order = 10, author = "mybatisPlus")
    @Operation(summary = "获取个人形象表分页", description = "获取个人形象表分页")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultPersonalImageryInfoVoPage.class
                    )))
    @PostMapping(value = "/page")
    @Parameters({
            @Parameter(name = "pageNum", description = "页码", required = false),
            @Parameter(name = "pageSize", description = "每页大小", required = false)
    })
    public Result<Page<PersonalImageryInfoVo>> getPage(@RequestParam(value = "pageNum", required = false) Long pageNum,
                                                       @RequestParam(value = "pageSize", required = false) Long pageSize,
                                                       @RequestBody(required = false) PersonalImageryInfoVo personalImageryInfoVo) {
        return Result.success(personalImageryInfoService.getPage(pageNum, pageSize, personalImageryInfoVo));
    }

    @ApiOperationSupport(order = 10, author = "mybatisPlus")
    @Operation(summary = "获取个人形象", description = "获取个人形象")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultPersonalImageryInfoVoList.class
                    )))
    @PostMapping(value = "/getList")
    @Tag(name = "我的", description = "我的")
    public Result<List<PersonalImageryInfoVo>> getList(@RequestBody(required = false) PersonalImageryInfoVo personalImageryInfoVo) throws Exception {
        return Result.success(personalImageryInfoService.getList(personalImageryInfoVo));
    }

    @ApiOperationSupport(order = 20, author = "mybatisPlus")
    @Operation(summary = "获取个人形象表详情", description = "获取个人形象表详情")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultPersonalImageryInfoVo.class
                    )))
    @Parameters({
            @Parameter(name = "id", description = "id", required = true, schema = @Schema(implementation = Long.class, type = "Long", example = "1"))
    })
    @GetMapping
    public Result<PersonalImageryInfoVo> query(@RequestParam(value = "id") Long id) {
        return Result.success(personalImageryInfoService.queryPersonalImageryInfo(id));
    }

    @AvoidRepeatableCommit
    @ApiOperationSupport(order = 30, author = "mybatisPlus")
    @Operation(summary = "新增个人形象表", description = "新增个人形象表")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultPersonalImageryInfoVo.class)))
    @PostMapping(value = "/addPersonalImageryInfo")
    @Parameters({
            @Parameter(name = "userId", description = "用户id", required = false),
            @Parameter(name = "position", description = "位置", required = false)
    })
    @Tag(name = "我的", description = "我的")
    public Result<PersonalImageryInfoVo> add(@RequestParam(value = "userId") Long userId,
                                             @RequestParam(value = "position") Integer position,
                                             @RequestPart(value = "file") MultipartFile file) throws Exception {
        PersonalImageryInfoVo personalImageryInfoVo = new PersonalImageryInfoVo();
        personalImageryInfoVo.setUserId(userId);
        personalImageryInfoVo.setPosition(position);
        return Result.success(personalImageryInfoService.addPersonalImageryInfo(personalImageryInfoVo, file));
    }

    @ApiOperationSupport(order = 40, author = "mybatisPlus")
    @Operation(summary = "修改个人形象表", description = "修改个人形象表",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = PersonalImageryInfoVo.class))
            ))
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultPersonalImageryInfoVo.class)))
    @PutMapping
    public Result<PersonalImageryInfoVo> update(@Validated({Update.class}) @RequestBody PersonalImageryInfoVo personalImageryInfoVo) {
        return Result.success(personalImageryInfoService.updatePersonalImageryInfo(personalImageryInfoVo));
    }

    @ApiOperationSupport(order = 50, author = "mybatisPlus")
    @Operation(summary = "刪除个人形象表", description = "刪除个人形象表")
    @Parameters({
            @Parameter(name = "ids", description = "ids,用，分割", required = true, schema = @Schema(implementation = String.class, type = "String", example = "1,2"))
    })
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultBoolean.class)))
    @DeleteMapping
    @Tag(name = "我的", description = "我的")
    public Result<Boolean> delete(@RequestParam("ids") String ids) {
        return Result.success(personalImageryInfoService.deletePersonalImageryInfo(ids));
    }
}
